package com.yanggu.scala.chapater13.partial

object PartialFunDemo03 {

  def main(args: Array[String]): Unit = {
    //偏函数可以进行简写
    //方式1。简写成case语句
    def partialFun1: PartialFunction[Any, Int] = {
      case i: Int => i + 1
      case j: Double => (2 * j).toInt
    }

    val list = List(1, 2, 3, 4, 1.2, 1.6, "Hello")
    println(list.collect(partialFun1))

    //方式2.
    val list1 = list.collect {
      case i: Int => i + 1
      case j: Double => (2 * j).toInt
      case k: Float => (3 * k).toInt
    }
    println(list1)
  }

}
